package org.example.Day10.bank;

public class Account {
    private String cardId;
    private double money;
    //private final lock lk = new Reentrantlock(); 创建锁对象
    public Account(){

    }
    public Account(String cardId,double money){
        this.cardId = cardId;
        this.money = money;
    }
    public void drawMoney(double money){
        //在void 前加synchronized实现同步方法，锁住方法
        String  name = Thread.currentThread().getName();
        //同步代码块
        synchronized (this) {
            //try{
            //lk.lock();
            if (this.money >= money) {
                System.out.println(name + "来取钱" + money + "成功");
                this.money -= money;
                System.out.println(name + "来取钱后,余额" + this.money);

            } else {
                System.out.println(name + "来取钱:余额不足");
            }
            //}catch(Exception e){
            //e.printStackTrace();
            //}finally{
            //lk.unlock()

        }
    }

    public String getCardId() {
        return cardId;
    }

    public void setCardId(String cardId) {
        this.cardId = cardId;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }
}
